// pages/set/set.js
const app = getApp()
var util = require('../../utils/util.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    mobile: '',
    form_data:{mobile:'',token:wx.getStorageSync('token')},
    yzmCode: 30,
    password: '',
    password2: '',
    getCode: "1",
    login_timer: false
  },bindinput(e){
    util.bindinput(e,this,'form_data')
  },
  //获取验证码
  getCode: function() { //发送验证码按钮
    var that = this;
    var yzmCode = that.data.yzmCode;
    if(that.data.login_timer) return;
    that.setData({login_timer: true,getCode: "3"})
    let timer = setInterval(() => {
      yzmCode--;
      that.setData({
        yzmCode
      })
      if(yzmCode=== -1){
        clearInterval(timer);
        that.setData({
          getCode: "2",
          yzmCode: 60,
          login_timer: false
        })
      }
    },1000)
    app.https_request(util.web_url.get_code_check,{mobile:this.data.mobile,token:wx.getStorageSync('token')},'POST',false,false,this,getCurrentPages()).then( (res)=>{
     
    }).catch( (errMsg)=>{});
  },onConfirm(){
    app.https_request(util.web_url.check_password,this.data.form_data,'POST',false,false,this,getCurrentPages()).then( (res)=>{
     console.log(res)
      if(res.code == 1){
       wx.switchTab({
       
         url: '/pages/my/my',
       })
     }else{
       util.msg(res.msg)
     }
    }).catch( (errMsg)=>{});
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
 this.setData({'form_data.token':util.login_id(),'form_data.mobile':wx.getStorageSync('userinfo').mobile});
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
this.setData({mobile:wx.getStorageSync('userinfo').mobile})
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})